package com.leyou.search.web;

import com.leyou.common.dto.PageDTO;
import com.leyou.search.dto.GoodsDTO;
import com.leyou.search.dto.SearchRequest;
import com.leyou.search.service.SearchService;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author 虎哥
 */
@RestController
@RequestMapping("goods")
public class SearchController {

    private final SearchService searchService;

    public SearchController(SearchService searchService) {
        this.searchService = searchService;
    }

    /**
     * 搜索商品
     * @param request 搜索条件
     * @return 当前页商品
     */
    @PostMapping("page")
    public ResponseEntity<PageDTO<GoodsDTO>> searchGoods(@RequestBody SearchRequest request){
        return ResponseEntity.ok(searchService.searchGoods(request));
    }

    /**
     * 搜索商品
     * @param request 搜索条件
     * @return 当前页商品
     */
    @PostMapping("filters")
    public ResponseEntity<Map<String, List<?>>> getFilters(@RequestBody SearchRequest request){

        return ResponseEntity.ok(searchService.getFilters(request));
    }
}
